<template>
  <div>
    <Navbar :title="title" :xiaoming="reserve" />
    <!-- 搜索开始 -->
    <div class="box">
      <!-- 左边区域 -->
      <div class="left">
        <div class="zuo" ref="form">
          <!-- 编码区域 -->
          <div class="small">
            <div class="sname">Banner页码</div>
            <div class="frame">
              <el-input placeholder v-model="input1" clearable></el-input>
            </div>
          </div>
          <!-- 商品名称区域 -->
          <div class="small">
            <div class="sname">Banner位置</div>
            <div class="frame">
              <el-input placeholder v-model="input2" clearable></el-input>
            </div>
          </div>
          <!-- 订单编号区域 -->
          <div class="small">
            <div class="sname">Banner每页数据</div>
            <div class="frame">
              <el-input placeholder v-model="input" clearable></el-input>
            </div>
          </div>

          <!-- 新增 -->
          <el-button class="add" type="primary" @click="dialog = true; " size="small">新增</el-button>
          <!-- 添加出现页面 -->

          <el-drawer title="再添加Banner" :visible.sync="dialog ">
            <span>
              我来啦!
              <BannerAdd ref="RuleForm" @close="close" />
            </span>
          </el-drawer>
        </div>

        <div class="you">
          <el-button type="primary" @click=" searchnum()">查询</el-button>
          <el-button type="primary" @click="reset()">重置</el-button>
        </div>
      </div>
      <!-- 右边区域 -->
      <div class="right"></div>
    </div>
    <!-- 搜索结束 -->
    <el-table
      :data="tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
      style="width: 100%"
    >
      <el-table-column label="ID" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">
            {{
            scope.row.bid}}
          </span>
        </template>
      </el-table-column>

      <el-table-column label="图片路径" width="180">
        <template slot-scope="scope">
          <img :src="scope.row.img" />
          <!-- 展示图片，不然就是地址 -->
          <!-- <span style="margin-left: 10px">{{ scope.row.img }}</span> -->
        </template>
      </el-table-column>

      <el-table-column label="Banner位置" width="130">
        <template slot-scope="scope">
          <span style="margin-left: 3px">{{ scope.row.imglocal }}</span>
        </template>
      </el-table-column>

      <el-table-column label="状态" width="180">
        <el-tooltip :content="'Switch value: ' + value" placement="top">
          <el-switch
            v-model="value"
            active-color="#0099ff"
            inactive-color="#cccccc"
            active-value="100"
            inactive-value="0"
          ></el-switch>
        </el-tooltip>
      </el-table-column>
      <el-table-column label="上架日期" width="180">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.beforetime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="下架日期" width="180">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.aftertime }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="handleDelete(scope.row.bid)">删除</el-button>
          <el-button size="mini" @click="drawer = true" type="success" style="margin-left: 16px;">编辑</el-button>
          <!-- 添加出现页面 -->

          <el-drawer title="再编辑Banner" :visible.sync="drawer">
            <span>我来啦!</span>
            <!--  -->
            <AddView ref="RuleForm" @close="close" />
          </el-drawer>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5,10]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="tableData.length"
    ></el-pagination>
  </div>
</template>

<script>
import Navbar from "../../components/NavBar.vue";
import { gmlist, gmdelete, gmblursearch } from "../../api/link.js";

import AddView from "../../components/Gm/AddView.vue";
import BannerAdd from "../../components/Gm/BannerAdd.vue";

export default {
  components: {
    AddView,
    BannerAdd,
    Navbar
  },
  data() {
    return {
      title: "轮播图管理",
      reserve: "返回上一层",
      // 搜索
      input1: "",
      input2: "",
      input: "",
      currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 4,
      drawer: false,
      dialog: false,
      value: "100",
      direction: "rtl",
      tableData: [
        //     {
        //     id: '01',
        //     beforetime: '2016-05-02',
        //     aftertime: '2016-05-02',
        //     imglocal:"A",
        //     img: 'https://m11.360buyimg.com/babel/s1065x360_jfs/t1/214993/34/25271/40945/63d8def9F3fe99025/7304b8c5d72f4953.jpg!q70.dpg.webp',
        // }, {
        //     id: '02',
        //     beforetime: '2016-05-04',
        //     aftertime: '2016-05-02',
        //     imglocal:"B",
        //     img: 'https://m11.360buyimg.com/babel/s1065x360_jfs/t1/214993/34/25271/40945/63d8def9F3fe99025/7304b8c5d72f4953.jpg!q70.dpg.webp',
        // },
        //     {
        //         id: '03',
        //         beforetime: '2016-05-01',
        //         aftertime: '2016-05-02',
        //         img: 'https://m11.360buyimg.com/babel/s1065x360_jfs/t1/214993/34/25271/40945/63d8def9F3fe99025/7304b8c5d72f4953.jpg!q70.dpg.webp',
        //         address: '上海市普陀区金沙江路 1519 弄'
        //     }, {
        //         id: '04',
        //         beforetime: '2016-05-03',
        //         aftertime: '2016-05-02',
        //         img: 'https://m11.360buyimg.com/babel/s1065x360_jfs/t1/214993/34/25271/40945/63d8def9F3fe99025/7304b8c5d72f4953.jpg!q70.dpg.webp',
        //         address: '上海市普陀区金沙江路 1516 弄'
        //     }
      ],
      currentPage: 1,
      total: 21,
      pageSize: 4
    };
  },

  methods: {
    //重置
    reset() {
      (this.input2 = ""),
        (this.input1 = ""),
        (this.value1 = ""),
        (this.input = ""),
        (this.value = ""),
        gmblursearch(this.current, this.size).then(res => {
          // console.log(res.data.data.records);
          // this.UPTEXTA(res.data.data.records)
          this.$store.commit("UPTEXTA", res.data.records);
        });
    },

    // 搜索
    searchnum() {
      // this.search = this.input1;
      // this.search = this.input2;
      // this.search = this.input;
      console.log(this.input1);
      console.log(this.input2);
      console.log(this.input);
      gmblursearch(this.input1, this.input2, this.input).then(ok => {
        // console.log(ok);
        // console.log(this.search);
        console.log(ok.data.records);
        this.tableData = ok.data.records;
      });
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.currentPage = 1;
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
    },
    // 列表
    getlist() {
      gmlist().then(ok => {
        console.log(ok.data);
        this.tableData = ok.data.records;
        console.log(this.tableData.length);
      });
    },
    //编辑
    banneradd() {
      this.drawer = true;
      this.getlist();
    },
    gmblursearch() {
      this.getlist();
    },
    close() {
      this.getList;
    },
    handleDelete(i) {
      console.log(i);
      //删除
      gmdelete(i).then(ok => {
        console.log(ok);
        this.getlist();
      });
      this.$confirm("亲，想好再删除哦！, 是否继续?", "删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  },

  mounted() {
    this.getlist();
  }
};
</script>

<style lang="scss" scoped>
//搜索样式

.box {
  width: 100%;
  height: 120px;
  margin-top: 10px;

  display: flex;

  // 左边区域
  .left {
    width: 90%;
    height: 100%;

    display: flex;

    // 左边区域左盒子
    .zuo {
      width: 75%;
      height: 100%;
      display: flex;
      flex-wrap: wrap;

      .small {
        width: 33.33%;
        height: 50%;
        display: flex;
        flex-shrink: 0;
        font-size: 12px;

        // 名称区域
        .sname {
          width: 40%;
          height: 40px;

          text-align: center;
          line-height: 40px;
        }

        .frame {
          width: 60%;
          height: 30px;

          .el-date-editor {
            width: 135px;
          }
        }
      }
    }

    // 右边区域右盒子
    .you {
      width: 25%;
      height: 100%;

      .el-button {
        margin-left: 40px;
      }
    }
  }

  // 右边区域
  .rigth {
    width: 10%;
    height: 100%;
    background-color: darkgoldenrod;
  }
}
//
.el-table .cell {
  width: 100px;
  height: 100px;
  img {
    width: 80%;
  }
}
.add {
  margin-left: 20px;
  margin-bottom: 20px;
}
.nav {
  background-color: #eeeeee;
}
</style>